using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Collections.ObjectModel;
using System.ComponentModel;

namespace AfterEdge.Web.UI
{
    public class PromptTriggerCollection : Collection<PromptTrigger> { }

    public abstract class PromptTrigger
    {
        private String _targetControlId;
        private String _eventName;
        private String _scriptCondition;
        private bool _preventDefault;
        private TriggerControlType _targetControlType = TriggerControlType.WebControl;

        private Prompt _prompt;

        protected PromptTrigger() { }
        
        protected PromptTrigger(TriggerControlType controlType)
        {
            this._targetControlType = controlType;
        }

        protected internal String TargetControlID
        {
            get { return this._targetControlId; }
            set { this._targetControlId = value; }
        }

        protected internal TriggerControlType TargetControlType
        {
            get { return this._targetControlType; }
            set { this._targetControlType = value; }
        }

        protected internal bool PreventDefault
        {
            get { return this._preventDefault; }
            set { this._preventDefault = value; }
        }

        /// <summary>
        /// Gets or sets the name of the event that causes this trigger to fire.
        /// </summary>
        /// <value>The name of the event.</value>
        [PersistenceMode(PersistenceMode.Attribute)]
        [Category("Behavior")]
        public String EventName
        {
            get { return this._eventName; }
            set { this._eventName = value; }
        }

        /// <summary>
        /// Gets or sets the script condition that fires before the trigger executes.
        /// </summary>
        /// <value>The script condition.</value>
        [PersistenceMode(PersistenceMode.Attribute)]
        [Category("Behavior")]
        public String ScriptCondition
        {
            get { return this._scriptCondition; }
            set { this._scriptCondition = value; }
        }

        [Browsable(false)]
        public Prompt Prompt
        {
            get { return this._prompt; }
        }

        internal void SetPrompt(Prompt prompt)
        {
            this._prompt = prompt;
        }
    }

    public class PagePromptTrigger : PromptTrigger
    {
        public PagePromptTrigger(String eventName) : this()
        {
            this.EventName = eventName;
        }
        
        public PagePromptTrigger() : base(TriggerControlType.PageControl) 
        {
            base.TargetControlID = "window";
        }
    }

    public class ControlPromptTrigger : PromptTrigger
    {
        public ControlPromptTrigger() { }

        public ControlPromptTrigger(String controlId, String eventName) : this(controlId, eventName, TriggerControlType.WebControl) { }
        public ControlPromptTrigger(String controlId, String eventName, TriggerControlType controlType)
        {
            this.ControlID = controlId;
            this.EventName = eventName;
            this.ControlType = controlType;
        }


        /// <summary>
        /// Gets or sets the control ID that will cause this trigger to fire.
        /// </summary>
        /// <value>The control ID.</value>
        [PersistenceMode(PersistenceMode.Attribute)]
        [Category("Behavior")]
        public String ControlID
        {
            get { return this.TargetControlID; }
            set { this.TargetControlID = value; }
        }

        /// <summary>
        /// Gets or sets the type of the control of the Control ID.
        /// </summary>
        /// <value>The type of the control.</value>
        [PersistenceMode(PersistenceMode.Attribute)]
        [Category("Behavior")]
        public TriggerControlType ControlType
        {
            get { return base.TargetControlType; }
            set { base.TargetControlType = value; }
        }

        /// <summary>
        /// Gets or sets a value indicating whether to prevent the default action on the trigger.
        /// </summary>
        /// <value><c>true</c> if [prevent default]; otherwise, <c>false</c>.</value>
        [PersistenceMode(PersistenceMode.Attribute)]
        [Category("Behavior")]
        public new bool PreventDefault
        {
            get { return base.PreventDefault; }
            set { base.PreventDefault = value; }
        }
    }
}
